"""
数据库备份脚本
生成时间: 2025-11-12 11:56:04
用途: 备份数据库文件
"""

import os
import shutil
from datetime import datetime

def backup_database():
    """备份数据库"""
    db_path = 'database/eqsystem.db'
    backup_dir = 'database/backups'
    
    # 确保备份目录存在
    os.makedirs(backup_dir, exist_ok=True)
    
    # 创建备份文件名（包含时间戳）
    timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
    backup_path = os.path.join(backup_dir, f'eqsystem_backup_{timestamp}.db')
    
    try:
        # 复制数据库文件
        shutil.copy2(db_path, backup_path)
        print(f"数据库已备份至: {backup_path}")
        return backup_path
    except Exception as e:
        print(f"备份过程中发生错误: {e}")
        raise

if __name__ == "__main__":
    backup_database()
